﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using XQ.SP.Model;

namespace XQ.SP.BllServices{
	 	//用户
		public partial class UserInfoBLL : BaseBll
	{
   		     
		private readonly XQ.SP.DalServices.UserInfoDal dal=new XQ.SP.DalServices.UserInfoDal();
		public UserInfoBLL()
		{}
		
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool ExistsWhere(string whereSql)
		{
			return dal.ExistsWhere(whereSql);
		}
		
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(long Id)
		{
			return dal.Exists(Id);
		}

		
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public long  Add(XQ.SP.Model.UserInfoItem model)
		{
			return dal.Add(model);	
		}

		/// <summary>
		/// 批量增加数据
		/// </summary>
		public bool  AddList(List<XQ.SP.Model.UserInfoItem> models)
		{
            int rows=dal.AddList(models);
            if (rows > 0)
                return true;
            else
                return false;
		}


		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XQ.SP.Model.UserInfoItem model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 批量更新数据
		/// </summary>
		public int UpdateList(List<XQ.SP.Model.UserInfoItem> models)
		{
			return dal.UpdateList(models);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long Id)
		{
			
			return dal.Delete(Id);
		}
				/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return dal.DeleteList(Idlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XQ.SP.Model.UserInfoItem GetModel(long Id)
		{
			
			return dal.GetModel(Id);
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XQ.SP.Model.UserInfoItem GetModelWhereStr(string whereSql)
		{
			
			return dal.GetModelWhereStr(whereSql);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere="")
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<XQ.SP.Model.UserInfoItem> GetModelList(string strWhere="")
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		
        /// <summary>
        /// 获得新增的数据
        /// </summary>
        public List<XQ.SP.Model.UserInfoItem> GetModelListNew(string datetimeStr)
        {
            DataSet ds = dal.GetList(" Created>='"+datetimeStr+"' ");
            return DataTableToList(ds.Tables[0]);
        }
        
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<XQ.SP.Model.UserInfoItem> DataTableToList(DataTable dt)
		{
			List<XQ.SP.Model.UserInfoItem> modelList = new List<XQ.SP.Model.UserInfoItem>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				XQ.SP.Model.UserInfoItem model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new XQ.SP.Model.UserInfoItem();					
													if(dt.Rows[n]["Id"].ToString()!="")
				{
					model.Id=long.Parse(dt.Rows[n]["Id"].ToString());
				}
																																				model.UserName= dt.Rows[n]["UserName"].ToString();
																																model.Email= dt.Rows[n]["Email"].ToString();
																																model.IDCard= dt.Rows[n]["IDCard"].ToString();
																																model.Mobil= dt.Rows[n]["Mobil"].ToString();
																																model.RealName= dt.Rows[n]["RealName"].ToString();
																																model.UserPassword= dt.Rows[n]["UserPassword"].ToString();
																																model.Telephone= dt.Rows[n]["Telephone"].ToString();
																																model.QQ= dt.Rows[n]["QQ"].ToString();
																												if(dt.Rows[n]["Sex"].ToString()!="")
				{
					model.Sex=int.Parse(dt.Rows[n]["Sex"].ToString());
				}
																																if(dt.Rows[n]["Birthday"].ToString()!="")
				{
					model.Birthday=DateTime.Parse(dt.Rows[n]["Birthday"].ToString());
				}
																																				model.Address= dt.Rows[n]["Address"].ToString();
																																model.Description= dt.Rows[n]["Description"].ToString();
																																model.PhotoPath= dt.Rows[n]["PhotoPath"].ToString();
																												if(dt.Rows[n]["CreateTime"].ToString()!="")
				{
					model.CreateTime=DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
				}
																																if(dt.Rows[n]["UpLoginTime"].ToString()!="")
				{
					model.UpLoginTime=DateTime.Parse(dt.Rows[n]["UpLoginTime"].ToString());
				}
																																if(dt.Rows[n]["Integral"].ToString()!="")
				{
					model.Integral=int.Parse(dt.Rows[n]["Integral"].ToString());
				}
																																if(dt.Rows[n]["Degree"].ToString()!="")
				{
					model.Degree=int.Parse(dt.Rows[n]["Degree"].ToString());
				}
																																if(dt.Rows[n]["Attest"].ToString()!="")
				{
					model.Attest=int.Parse(dt.Rows[n]["Attest"].ToString());
				}
																																if(dt.Rows[n]["PostsCount"].ToString()!="")
				{
					model.PostsCount=int.Parse(dt.Rows[n]["PostsCount"].ToString());
				}
																																if(dt.Rows[n]["PostsSaidCount"].ToString()!="")
				{
					model.PostsSaidCount=int.Parse(dt.Rows[n]["PostsSaidCount"].ToString());
				}
																																if(dt.Rows[n]["GoodSaidCount"].ToString()!="")
				{
					model.GoodSaidCount=int.Parse(dt.Rows[n]["GoodSaidCount"].ToString());
				}
																																if(dt.Rows[n]["IsSaleUser"].ToString()!="")
				{
					model.IsSaleUser=int.Parse(dt.Rows[n]["IsSaleUser"].ToString());
				}
																																				model.SaleUserTitle= dt.Rows[n]["SaleUserTitle"].ToString();
																																model.SaleUserFile= dt.Rows[n]["SaleUserFile"].ToString();
																												if(dt.Rows[n]["ShopUserTypeId"].ToString()!="")
				{
					model.ShopUserTypeId=long.Parse(dt.Rows[n]["ShopUserTypeId"].ToString());
				}
																																if(dt.Rows[n]["ParentId"].ToString()!="")
				{
					model.ParentId=long.Parse(dt.Rows[n]["ParentId"].ToString());
				}
																																if(dt.Rows[n]["UsefulCount"].ToString()!="")
				{
					model.UsefulCount=int.Parse(dt.Rows[n]["UsefulCount"].ToString());
				}
																																if(dt.Rows[n]["UMoney"].ToString()!="")
				{
					model.UMoney=int.Parse(dt.Rows[n]["UMoney"].ToString());
				}
																																if(dt.Rows[n]["UserType"].ToString()!="")
				{
					model.UserType=int.Parse(dt.Rows[n]["UserType"].ToString());
				}
																																if(dt.Rows[n]["Status"].ToString()!="")
				{
					model.Status=int.Parse(dt.Rows[n]["Status"].ToString());
				}
																																if(dt.Rows[n]["Creator"].ToString()!="")
				{
					model.Creator=long.Parse(dt.Rows[n]["Creator"].ToString());
				}
																																if(dt.Rows[n]["Created"].ToString()!="")
				{
					model.Created=DateTime.Parse(dt.Rows[n]["Created"].ToString());
				}
																																if(dt.Rows[n]["Modifier"].ToString()!="")
				{
					model.Modifier=long.Parse(dt.Rows[n]["Modifier"].ToString());
				}
																																if(dt.Rows[n]["Modified"].ToString()!="")
				{
					model.Modified=DateTime.Parse(dt.Rows[n]["Modified"].ToString());
				}
																																if(dt.Rows[n]["ShopUserTeamApply"].ToString()!="")
				{
					model.ShopUserTeamApply=long.Parse(dt.Rows[n]["ShopUserTeamApply"].ToString());
				}
																																if(dt.Rows[n]["ShopUserTeamId"].ToString()!="")
				{
					model.ShopUserTeamId=long.Parse(dt.Rows[n]["ShopUserTeamId"].ToString());
				}
																										
				
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
		

   
		/// <summary>
		/// Model的属性对应赋值
		/// </summary>
		public void ModelCopy(XQ.SP.Model.UserInfoItem modelOld,XQ.SP.Model.UserInfoItem modelNew)
		{
			            
            modelNew.Id = modelOld.Id;
                        
            modelNew.UserName = modelOld.UserName;
                        
            modelNew.Email = modelOld.Email;
                        
            modelNew.IDCard = modelOld.IDCard;
                        
            modelNew.Mobil = modelOld.Mobil;
                        
            modelNew.RealName = modelOld.RealName;
                        
            modelNew.UserPassword = modelOld.UserPassword;
                        
            modelNew.Telephone = modelOld.Telephone;
                        
            modelNew.QQ = modelOld.QQ;
                        
            modelNew.Sex = modelOld.Sex;
                        
            modelNew.Birthday = modelOld.Birthday;
                        
            modelNew.Address = modelOld.Address;
                        
            modelNew.Description = modelOld.Description;
                        
            modelNew.PhotoPath = modelOld.PhotoPath;
                        
            modelNew.CreateTime = modelOld.CreateTime;
                        
            modelNew.UpLoginTime = modelOld.UpLoginTime;
                        
            modelNew.Integral = modelOld.Integral;
                        
            modelNew.Degree = modelOld.Degree;
                        
            modelNew.Attest = modelOld.Attest;
                        
            modelNew.PostsCount = modelOld.PostsCount;
                        
            modelNew.PostsSaidCount = modelOld.PostsSaidCount;
                        
            modelNew.GoodSaidCount = modelOld.GoodSaidCount;
                        
            modelNew.IsSaleUser = modelOld.IsSaleUser;
                        
            modelNew.SaleUserTitle = modelOld.SaleUserTitle;
                        
            modelNew.SaleUserFile = modelOld.SaleUserFile;
                        
            modelNew.ShopUserTypeId = modelOld.ShopUserTypeId;
                        
            modelNew.ParentId = modelOld.ParentId;
                        
            modelNew.UsefulCount = modelOld.UsefulCount;
                        
            modelNew.UMoney = modelOld.UMoney;
                        
            modelNew.UserType = modelOld.UserType;
                        
            modelNew.Status = modelOld.Status;
                        
            modelNew.Creator = modelOld.Creator;
                        
            modelNew.Created = modelOld.Created;
                        
            modelNew.Modifier = modelOld.Modifier;
                        
            modelNew.Modified = modelOld.Modified;
                        
            modelNew.ShopUserTeamApply = modelOld.ShopUserTeamApply;
                        
            modelNew.ShopUserTeamId = modelOld.ShopUserTeamId;
            		}
#endregion
   
	}
}